<template>
	<view class="ts-flex ts-column">
		<ts-banner image="https://via.placeholder.com/750x500.png" :height="250"></ts-banner>
		<ts-search-bar v-model="keywords" @search="doSearch"></ts-search-bar>

		<view class="ts-list">
			<view class="ts-list-cell" hover-class="ts-list-cell-hover" v-for="(item,index) in list" :key="index">
				<view class="ts-media-list">
					<image class="ts-media-list-logo" :src="item.user.head_image"></image>
					<view class="ts-flex ts-flex-item ts-column">
						<view class="ts-flex ts-row" style="justify-content: space-between;">
							<view class="ts-row ts-flex" style="align-items: center;">
								<view class="ts-h4">{{item.user.name}}</view>
								<view class="ts-h5 ts-padding-left">{{item.contact}}</view>
							</view>
							<view class="ts-row ts-flex-item" style="justify-content: flex-end;">
								<ts-badge v-if="item.status.length>0" :type="'success'" :text="item.status"></ts-badge>
								<ts-badge :type="item.type==='丢失'? 'danger':'primary'" :text="item.type"></ts-badge>
							</view>
						</view>
						<view class="ts-flex ts-column ts-flex-item ts-padding-top ts-padding-bottom">
							<text class="ts-flex">{{item.content}}</text>
						</view>
						<view class="ts-row ts-flex" style="flex-wrap: wrap; align-items: center;">
							<image v-for="(img, index2) in item.images" :key="index2" class="image-box" :src="img"></image>
						</view>
						<view class="ts-h5 ts-padding-top">{{item.address}}</view>
						<view class="ts-h5 ts-padding-top">{{item.time}}</view>
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import tsBanner from 'components/teaset/components/ts-banner.vue';
	import tsSearchBar from 'components/teaset/components/ts-search-bar.vue';
	import tsBadge from 'components/teaset/components/ts-badge.vue';

	var self;
	export default {
		components: {
			tsBanner,
			tsSearchBar,
			tsBadge
		},
		data: {
			keywords: 'Hello!',
			page: 1,
			list: [],
		},
		onLoad(e) {
			self = this;
			const api = 'https://www.easy-mock.com/mock/5bcd1a3d5f4b6e63fbb101cc/course/api/app/lost-found/getEventList';
			uni.request({
				url: api,
				method: 'GET',
				data: {
					keywords: self.keywords,
					page: self.page,
				},
				dataType: 'json',
				success(response) {
					const res = response.data;
					console.log(JSON.stringify(res));
					//           res= {
					//             data:[],
					//             success:true,
					//             message:'',
					//             page:1,
					//             has_more:true
					//           }

					if (res.success) {
						if (res.data) {
							self.list = self.list.concat(res.data);
						}
					} else {
						console.log(res.message)
					}
				}
			})
		},
		methods: {
			doSearch() {
				console.log(this.keywords)
			}
		}
	}
</script>

<style>
	view {
		/* border: #000000 solid 1upx; */

		font-size: 32upx;
	}
  
  .image-box {
      height: 180upx;
      width: 180upx;
      padding-right: 10upx;
      padding-bottom: 10upx;
  }
</style>
